package com.fadadianqi.logistics.sell.service;

import com.fadadianqi.commons.PrimaryKeyCreator;
import com.fadadianqi.logistics.sell.dao.InOutDAO;
import com.fadadianqi.logistics.sell.model.InOut;
import com.yeqiangwei.commons.util.ArithHelper;
import com.yeqiangwei.commons.util.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class InOutService {


    public void create(InOut inOut) {
        if (inOut.getAddTime() == null) {
            inOut.setAddTime(new Date());
        }
        if (inOut.getId() == null) {
            inOut.setId(PrimaryKeyCreator.create());
        }
        inOutDAO.create(inOut);
    }

    public List<InOut> findAll(Pagination pagination) {
        return inOutDAO.findAll(pagination);
    }

    public int countAll() {
        return inOutDAO.countAll();
    }

    public List<InOut> findBetween(Date date1, Date date2, Pagination pagination) {
        return inOutDAO.findBetween(date1, date2, pagination);
    }

    public Integer countBetween(Date date1, Date date2) {
        return inOutDAO.countBetween(date1, date2);
    }

    public Double sumMoneyBetween(Date date1, Date date2) {
        Double d = inOutDAO.sumMoneyBetween(date1, date2);
        if (d != null) {
            d = ArithHelper.round(d, 2);
        }
        return d;
    }

    public Double totalMoney(int year) {
        Double d = inOutDAO.totalMoney(year);
        if (d != null) {
            d = ArithHelper.round(d, 2);
        }
        return d;
    }

    public Double outMoney(int year) {
        Double d = inOutDAO.outMoney(year);
        if (d != null) {
            d = ArithHelper.round(d, 2);
        }
        return d;
    }

    public Double inMoney(int year) {
        Double d = inOutDAO.inMoney(year);
        if (d != null) {
            d = ArithHelper.round(d, 2);
        }
        return d;
    }

    @Autowired
    private InOutDAO inOutDAO;

}
